<?php
/*
	插件页面增删查改
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['plugin_id']){
	$_SESSION['plugin_id']=intval($_RQ['plugin_id']);
}
if(!$_SESSION['plugin_id']){
	exi('请先选择插件！','error');
}
if($_RQ['op']=='list'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	$result=cloud_request('plugin.cpage.list',$params);
	if($result){
			foreach($result['list'] as &$page){
				$page['cpage_op']=array('action'=>'app_develop.plugin.cpage_op','query'=>'page_id='.$page['id'],'title'=>'页面功能设置');
				$page['edit_code']=array('action'=>'app_develop.plugin.edit_code','op'=>'edit','query'=>'id=/custom/actions/'.$page['name'].'.php');
			}
	}
	//print_r($result['list']);exit;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'页面列表'),
			array('op'=>'edit','title'=>'添加页面'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'name','title'=>'页面标识','type'=>'string'),
			array('name'=>'title','title'=>'页面名称','type'=>'string'),
			array('name'=>'cpage_op','title'=>'页面功能设置','type'=>'href'),
			array('name'=>'edit_code','title'=>'编辑代码','type'=>'href'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$result['htmls']=$htmls;
	exi($result);
}
if($_RQ['op']=='edit'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	$id=intval($_RQ['id']);
	if($id){
		$params['id']=$id;
	}
	
	$result=cloud_request('plugin.cpage.edit',$params);
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'设置页面信息',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'页面列表'),
			'1'=>array('op'=>'edit','title'=>'添加页面'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'页面标识','name'=>'name', 'help'=>'页面标识，支持字母、数字、大小写，必须以字母开头。且不能和已有功能标识重复' ),
			array('type'=>'string','title'=>'页面名称','name'=>'title' ),
			array('type'=>'select','title'=>'页面主op','name'=>'main_op' , 'options'=>'ops','option_value'=>'name'),
		)
	);
	$result['htmls']=$htmls;
	exi($result);
}
if($_RQ['op']=='post'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	$post=get_postdata();
	$params['postdata']=$post;
	$result=cloud_request('plugin.cpage.post',$params);
	exi($result,'','list');
}

if($_RQ['op'] == 'del'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
	}
	if($_RQ['del']){
		$params['del']=trim($_RQ['del']);
	}
	$result=cloud_request('plugin.cpage.del',$params);
	exi($result);
}